<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>工厂模式</title>
		<script>
			//1.需求: 张三给女儿做了一个玩具手机，编号001，粉色，会唧唧叫
			var playPhone1 = {
				name:"001",
				color:"pink",
				say1:function(){
					alert("唧唧喳喳"+"我是"+ this.name + this.color);
				}
			}
			playPhone1.say1();
			//1.需求: 张三给儿子做了一个玩具手机，编号002，黑色，会唧唧叫
			var playPhone2 = {
				name:"002",
				color:"black",
				say2:function(){
					alert("唧唧喳喳"+"我是"+ this.name + this.color);
				}
			}
			playPhone2.say2();
			
			//3.需求：张三亲戚家的小孩都要这个玩具，要张三做很多个，可以将原料图纸等东西交给工厂，让他们批量生产
			//-------------工厂模式()
			function createPhone(num,se,da){
				var playPhone = {
					name:num,
					color:se,
					size:da,
					sex:"man",
					say:function(){
						alert("唧唧喳喳"+"我是"+ this.name + this.color);
					}
			    }//封装好了创建对象的过程
			    return playPhone//返回对象（出厂）
			}
			
			var playPhone3 = createPhone("003","blue","5.0");//实例化对象
			playPhone3.say();
			var playPhone4 = createPhone("004","blue","5.0");//实例化对象
			playPhone4.say();
			var playPhone5 = createPhone("005","blue","5.0");//实例化对象
			playPhone5.say();
			
			
//			例子:需求:武汉市征兵,要男兵,要女兵,
//			都要会报自己的名字,身高,性别,如果是男兵还要体重,
//			女兵要会唱歌跳舞,要找10个兵苗子,
//			有男有女,其中要有5个符合要求

             function createPeople(xm,sg,nv,tz){
             	
             	var people = {
             		name:xm,//姓名
             		tall:sg,//身高
             		sex:nv,//性别
             		tiz:tz,//体重
             		cai:yi,
             		say1:funtion(){
             			if(this.sex == "男"){
             				this.tiz = tz;
             			   alert("我叫"+this.name + "身高" +this.tall + "是"+ this.sex + "体重"+ this.tiz);
             		    }else{
             		    	this.ti = "";
             		    	this.cai = yi;
             		    	alert("我叫"+this.name + "身高" +this.tall + "是"+ this.sex + "才艺"+ this.cai);
             		    }
             	  }
               }
             	return people;
             }
             var people1 = createPeople("xingming","171cm","男性");
             var people2 = createPeople("xingming","168cm","女性");
             var people3 = createPeople("xingming","178cm","男性");
             var people4 = createPeople("xingming","160cm","女性");
             var people5 = createPeople("xingming","168cm","女性");
             var people6 = createPeople("xingming","170cm","男性");
             var people7 = createPeople("xingming","168cm","女性");
             var people8 = createPeople("xingming","158cm","女性");
             var people9 = createPeople("xingming","168cm","女性");
             var people10 = createPeople("xingming","152cm","女性");
            
		</script>
	</head>
	<body>
	</body>
</html>
